<template>
  <div class="category">
    <van-search
      v-model="value"
      @search="onSearch"
      placeholder="请输入搜索关键词"
    ></van-search>
    <van-tabs scrollspy class="cate">
      <van-tab
        class="content"
        v-for="item in cateList"
        :title="item.cate_name"
        :key="item.id"
      >
        <span class="title">{{ item.cate_name }}</span>
        <ul>
          <router-link
            tag="li"
            v-for="i in item.children"
            :key="i.id"
            :to="{ path: `/goodlist/${i.id}`, query: { title: i.cate_name } }"
          >
            <van-image width="80" height="80" :src="i.pic" />
            {{ i.cate_name }}
          </router-link>
        </ul>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
export default {
  name: "Category",
  data() {
    return {
      cateList: [],
      value: "",
    };
  },
  props: {},
  created() {
    this.$axios.get("api/category").then((d) => {
      this.cateList = d.data.data;
      // console.log(this.cateList);
    });
  },
  methods: {
    onSearch() {
      // this.$axios
      //   .get("api/products", {
      //     page: 1,
      //     limit: 8,
      //     keyword: this.value,
      //     sid: 0,
      //     news: 0,
      //     priceOrder: "",
      //     salesOrder: "",
      //   })
      //   .then((d) => {
      //     console.log(d);
      //   });
      this.$router.push({
        path: "/goodlist/:id",
        query: { searchWord: this.value },
      });
    },
  },
};
</script>

<style lang="less">
.category {
  .van-search {
    position: fixed;
    width: 100%;
    top: 0px;
    z-index: 999;
    .van-search__content {
      border-radius: 30px;
      background-color: #f5f5f5;
    }
  }
  .cate {
    padding-top: 54px;
    .van-tabs__wrap {
      height: auto;
      position: fixed;
      left: 0;
      z-index: 999;
      width: 100px;
    }
    .van-tabs__nav {
      display: block;
      padding-left: 0px;
      .van-tab {
        line-height: 45px;
        font-size: 15px;
      }
      .van-tab--active {
        border-left: 2px solid #fc4141;
        color: #fc4141;
        background-color: #f7f7f7;
      }
      .van-tabs__line {
        display: none;
      }
    }
    .van-tabs__content {
      padding-left: 100px;
      overflow: hidden;
      margin-top: -50px;
      padding-bottom: 90px;
      .title {
        text-align: center;
        font-size: 15px;
        position: relative;
        display: inline-block;
        height: 70px;
        line-height: 70px;
      }
      .title::before {
        content: "";
        width: 50px;
        border: 1px solid #adadad;
        position: absolute;
        left: -65px;
        top: 35px;
        background-color: #adadad;
      }
      .title::after {
        content: "";
        width: 50px;
        border: 1px solid #adadad;
        position: absolute;
        right: -65px;
        top: 35px;
        background-color: #adadad;
      }
      .van-tab__pane {
        text-align: center;
        padding-top: 35px;
      }
      ul {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        li {
          width: 33%;
          text-align: center;
          display: flex;
          flex-direction: column;
          align-items: center;
          font-size: 14px;
          height: 115px;
          .van-image img {
            // width: 80%;
            border-radius: 50%;
          }
        }
      }
    }
  }
}
</style>